KString Class Reference

#include <kstring.h>

List of all members.


Detailed Description

Utility class to manipulate strings.

Definition at line 97 of file kstring.h.


Padding

enum   PaddingType
  Padding types. More...
KString  Pad (PaddingType pPadding, size_t pLen, char pCar= ' ') const
  Add padding characters.
KString  UnPad (PaddingType pPadding) const
  Remove padding characters.

Constructors and Destructor

static KString Create ()
  Create an instance.
static KString Create (KString *pString)
  Create an instance if not already allocated ( is null ).
static KString DestroyIfEmpty (KString *pString)
  Destroy the allocated space if empty.
static KString StringOrEmpty (KString *pString)
  Return the passed pString if it is not empty, or a local static empty KString will be returned.
void  Destroy ()
  Destroy an allocated version of the string.

Memory Pool Management

static KMemoryAllocator AllocatorGet ()
  Get new memory allocator.
static void  AllocatorPurge ()
  Purge memory allocator.
static void  AllocatorRelease ()
  Release memory allocator.

Constructors and Destructor

  KString ()
  Default constructor.
  KString (const KString &pStr)
  Copy constructor.
  KString (const char *pStr)
  String constructor.
  KString (char pChar, size_t pNbRepeat=1)
  Character constructor.
  KString (const char *pCharPtr, size_t pLength)
  String constructor with maximum length.
  KString (const int pValue)
  Int constructor.
  KString (const float pValue)
  Float constructor.
  KString (const double pValue)
  Double constructor.
  ~KString ()
  Destructor.

Instance Validation.

bool  IsOK () const
  Return true if string is valid.
KString Invalidate ()
  Invalidate string.
size_t  GetLen () const
  Get string length like "C" strlen().
bool  IsEmpty () const
  Return true if string is of length 0.
KString Empty ()
  Discard the content of the object.

Buffer Access

char &  operator[] (int pIndex)
  Access by reference.
char  operator[] (int pIndex) const
  Access by copy.
  operator const char * () const
  Cast operator.
char *  Buffer ()
  Non-const buffer access.
const char *  Buffer () const
  const buffer access.

Assignment Operators

const KString operator= (const KString &pStr)
  KString assignment operator.
const KString operator= (char pChar)
  Character assignment operator.
const KString operator= (const char *pStr)
  String assignment operator.
const KString operator= (int pValue)
  Int assignment operator.
const KString operator= (float pValue)
  Float assignment operator.
const KString operator= (double pValue)
  Double assignment operator.
const KString Copy (size_t pLen, const char *pStr)
  String assignment function with maximum length.
void  Swap (KString &pStr)
  Swap the contents of two KString objects; no allocation is performed.

Append and Concatenation

const KString Append (const char *pStr)
  Append as "C" strcat().
const KString AppendN (const char *pStr, size_t pLength)
  Append as "C" strncat().
const KString operator+= (const KString &pKStr)
  KString append.
const KString operator+= (char pChar)
  Character append.
const KString operator+= (const char *pStr)
  String append.
const KString operator+= (int pValue)
  Int append.
const KString operator+= (float pValue)
  Float append.
KFBX_DLL KString  operator+ (const KString &pKStr1, const KString &pKStr2)
  KString concatenation.
KFBX_DLL KString  operator+ (const KString &pKStr, char pChar)
  Character concatenation.
KFBX_DLL KString  operator+ (const KString &pKStr, const char *pStr)
  String concatenation.
KFBX_DLL KString  operator+ (const KString &pKStr, int pValue)
  Int concatenation.
KFBX_DLL KString  operator+ (const KString &pKStr, float pValue)
  Float concatenation.

String Comparison

int  Compare (const char *pStr) const
  Compare as "C" strcmp().
int  CompareNoCase (const char *pStr) const
  Compare as "C" stricmp().
bool  operator== (const KString &pStr) const
  Equality operator.
bool  operator!= (const KString &pStr) const
  Inequality operator.
bool  operator< (const KString &pStr) const
  Inferior to operator.
bool  operator<= (const KString &pStr) const
  Inferior or equal to operator.
bool  operator>= (const KString &pStr) const
  Superior or equal to operator.
bool  operator> (const KString &pStr) const
  Superior to operator.
bool  operator== (const char *pStr) const
  Equality operator.
bool  operator!= (const char *pStr) const
  Inequality operator.
bool  operator< (const char *pStr) const
  Inferior to operator.
bool  operator<= (const char *pStr) const
  Inferior or equal to operator.
bool  operator>= (const char *pStr) const
  Superior or equal to operator.
bool  operator> (const char *pStr) const
  Superior to operator.

Substring Extraction

KString  Mid (size_t pFirst, size_t pCount) const
  Extract middle string for a given length.
KString  Mid (size_t pFirst) const
  Extract middle string up to the end.
KString  Left (size_t pCount) const
  Extract left string.
KString  Right (size_t pCount) const
  Extract right string.

Conversion

KString  Upper () const
  Uppercase conversion.
KString  Lower () const
  Lowercase conversion.
KString  Reverse () const
  Reverse conversion.
KString  ConvertToUnix () const
  Convert to Unix, changes \r\n characters for a single \n.
KString  ConvertToWindows () const
  Convert to Windows, changes \n character for both \r\n.

Search

int  Find (char pChar, size_t pStartPosition=0) const
  Look for a single character match, like "C" strchr().
int  Find (const char *pStrSub, size_t pStartPosition=0) const
  Look for a substring match, like "C" strstr().
int  ReverseFind (char pChar) const
  Look for a single character match, like "C" strrchr().
int  FindOneOf (const char *pStrCharSet, size_t pStartPosition=0) const
  Look for a single character match, like "C" strpbrk().
bool  FindAndReplace (const char *pFind, const char *pReplaceBy, size_t pStartPosition=0)
  Replace a substring.
bool  ReplaceAll (char pFind, char pReplaceBy)
  Replace a character.

Token Extraction

int  GetTokenCount (const char *pSpans) const
  Get number of tokens.
KString  GetToken (int pTokenIndex, const char *pSpans) const
  Get token at given index.

Member Enumeration Documentation

Padding types.

  • eRight
  • eLeft
  • eBoth

Definition at line 453 of file kstring.h.


Constructor & Destructor Documentation

KString (  ) 

Default constructor.

KString ( const KString pStr  ) 

Copy constructor.

Parameters:
pStr  The KString be copied.

KString ( const char *  pStr  ) 

String constructor.

Parameters:
pStr  The string used to construct KString.

KString ( char  pChar,
size_t  pNbRepeat = 1  
)

Character constructor.

Parameters:
pChar  The character used to construct KString.
pNbRepeat  The buffer size of KString.

KString ( const char *  pCharPtr,
size_t  pLength  
)

String constructor with maximum length.

Parameters:
pCharPtr  The string used to construct KString.
pLength  Maximum length.

KString ( const int  pValue  ) 

Int constructor.

Parameters:
pValue  The int value used to construct KString.

KString ( const float  pValue  ) 

Float constructor.

Parameters:
pValue  The float value used to construct KString.

KString ( const double  pValue  ) 

Double constructor.

Parameters:
pValue  The double value used to construct KString.

~KString (  ) 

Destructor.


Member Function Documentation

static KString* Create (  )  [static]

Create an instance.

static KString* Create ( KString pString  )  [static]

Create an instance if not already allocated ( is null ).

Parameters:
pString  KString used to creat a new KString.

void Destroy (  ) 

Destroy an allocated version of the string.

static KString* DestroyIfEmpty ( KString pString  )  [static]

Destroy the allocated space if empty.

Parameters:
pString  KString to be destroyed if empty.

static KString* StringOrEmpty ( KString pString  )  [static]

Return the passed pString if it is not empty, or a local static empty KString will be returned.

Parameters:
pString  If pString is not empty, pString will be returned, or a local static empty string will be returned.

bool IsOK (  )  const [inline]

Return true if string is valid.

Judge if this string is error.

Definition at line 657 of file kstring.h.

KString& Invalidate (  ) 

Invalidate string.

size_t GetLen (  )  const [inline]

Get string length like "C" strlen().

Get the length of this string.

Definition at line 659 of file kstring.h.

Referenced by IsEmpty(), and StripQuotationMarks().

bool IsEmpty (  )  const [inline]

Return true if string is of length 0.

Judge if this string is empty.

Definition at line 661 of file kstring.h.

References GetLen().

KString& Empty (  ) 

Discard the content of the object.

char& operator[] ( int  pIndex  ) 

Access by reference.

Parameters:
pIndex  The index.
Returns:
The reference of the char at pIndex.

char operator[] ( int  pIndex  )  const

Access by copy.

Parameters:
pIndex  The index.
Returns:
The char at pIndex.

operator const char * (  )  const [inline]

Cast operator.

Get the content of string .

Definition at line 668 of file kstring.h.

char * Buffer (  )  [inline]

Non-const buffer access.

Get the content of string.

Definition at line 664 of file kstring.h.

const char * Buffer (  )  const [inline]

const buffer access.

Get the content of string.

Definition at line 666 of file kstring.h.

const KString& operator= ( const KString pStr  ) 

KString assignment operator.

Parameters:
pStr  The KString to be assigned.

const KString& operator= ( char  pChar  ) 

Character assignment operator.

Parameters:
pChar  The character to be assigned.

const KString& operator= ( const char *  pStr  ) 

String assignment operator.

Parameters:
pStr  The string to be assigned.

const KString& operator= ( int  pValue  ) 

Int assignment operator.

Parameters:
pValue  The int value to be assigned.

const KString& operator= ( float  pValue  ) 

Float assignment operator.

Parameters:
pValue  The float value to be assigned.

const KString& operator= ( double  pValue  ) 

Double assignment operator.

Parameters:
pValue  The double value to be assigned.

const KString& Copy ( size_t  pLen,
const char *  pStr  
)

String assignment function with maximum length.

Parameters:
pLen  Maximum length.
pStr  The string to be assigned.

void Swap ( KString pStr  ) 

Swap the contents of two KString objects; no allocation is performed.

Parameters:
pStr  The KString to be swapped.

const KString& Append ( const char *  pStr  ) 

Append as "C" strcat().

Parameters:
pStr  The string to be appended.

const KString& AppendN ( const char *  pStr,
size_t  pLength  
)

Append as "C" strncat().

Parameters:
pStr  The string to be appended.
pLength  The length of chars to be appended.

const KString& operator+= ( const KString pKStr  ) 

KString append.

Parameters:
pKStr  The KString to be appended.

const KString& operator+= ( char  pChar  ) 

Character append.

Parameters:
pChar  The character to be appended.

const KString& operator+= ( const char *  pStr  ) 

String append.

Parameters:
pStr  The string to be appended.

const KString& operator+= ( int  pValue  ) 

Int append.

Parameters:
pValue  The int value to be appended.

const KString& operator+= ( float  pValue  ) 

Float append.

Parameters:
pValue  The float value to be appended.

int Compare ( const char *  pStr  )  const

Compare as "C" strcmp().

Parameters:
pStr  The string to be compared.

int CompareNoCase ( const char *  pStr  )  const

Compare as "C" stricmp().

Parameters:
pStr  The string to be compared.

bool operator== ( const KString pStr  )  const

Equality operator.

Parameters:
pStr  The KString to be compared.

bool operator!= ( const KString pStr  )  const

Inequality operator.

Parameters:
pStr  The KString to be compared.

bool operator< ( const KString pStr  )  const

Inferior to operator.

Parameters:
pStr  The KString to be compared.

bool operator<= ( const KString pStr  )  const

Inferior or equal to operator.

Parameters:
pStr  The KString to be compared.

bool operator>= ( const KString pStr  )  const

Superior or equal to operator.

Parameters:
pStr  The KString to be compared.

bool operator> ( const KString pStr  )  const

Superior to operator.

Parameters:
pStr  The KString to be compared.

bool operator== ( const char *  pStr  )  const

Equality operator.

Parameters:
pStr  The string to be compared.

bool operator!= ( const char *  pStr  )  const

Inequality operator.

Parameters:
pStr  The string to be compared.

bool operator< ( const char *  pStr  )  const

Inferior to operator.

Parameters:
pStr  The string to be compared.

bool operator<= ( const char *  pStr  )  const

Inferior or equal to operator.

Parameters:
pStr  The string to be compared.

bool operator>= ( const char *  pStr  )  const

Superior or equal to operator.

Parameters:
pStr  The string to be compared.

bool operator> ( const char *  pStr  )  const

Superior to operator.

Parameters:
pStr  The string to be compared.

KString Mid ( size_t  pFirst,
size_t  pCount  
) const

Extract middle string for a given length.

Parameters:
pFirst  The start index of KString to be extracted.
pCount  The length of sub-string to be extracted.

Referenced by RemoveChar(), and StripQuotationMarks().

KString Mid ( size_t  pFirst  )  const

Extract middle string up to the end.

Parameters:
pFirst  The start index of KString to be extracted.

KString Left ( size_t  pCount  )  const

Extract left string.

Parameters:
pCount  The length of sub-string to be extracted.

Referenced by RemoveChar().

KString Right ( size_t  pCount  )  const

Extract right string.

Parameters:
pCount  The length of sub-string to be extracted.

KString Pad ( PaddingType  pPadding,
size_t  pLen,
char  pCar = ' '  
) const

Add padding characters.

Parameters:
pPadding  The padding type.
pLen  The length limit of KString after padding.
pCar  The character to be padded.

KString UnPad ( PaddingType  pPadding  )  const

Remove padding characters.

Parameters:
pPadding  The padding type.

KString Upper (  )  const

Uppercase conversion.

KString Lower (  )  const

Lowercase conversion.

KString Reverse (  )  const

Reverse conversion.

KString ConvertToUnix (  )  const

Convert to Unix, changes \r\n characters for a single \n.

KString ConvertToWindows (  )  const

Convert to Windows, changes \n character for both \r\n.

int Find ( char  pChar,
size_t  pStartPosition = 0  
) const

Look for a single character match, like "C" strchr().

Parameters:
pChar  The character to look for.
pStartPosition  Start position to look for.
Returns:
Index or -1 if not found.

int Find ( const char *  pStrSub,
size_t  pStartPosition = 0  
) const

Look for a substring match, like "C" strstr().

Parameters:
pStrSub  The substring to look for.
pStartPosition  Start position to look for.
Returns:
Starting index or -1 if not found.

int ReverseFind ( char  pChar  )  const

Look for a single character match, like "C" strrchr().

Parameters:
pChar  The character to look for.
Returns:
Index or -1 if not found.

Referenced by RemoveChar().

int FindOneOf ( const char *  pStrCharSet,
size_t  pStartPosition = 0  
) const

Look for a single character match, like "C" strpbrk().

Parameters:
pStrCharSet  The character set.
pStartPosition  The start position.
Returns:
Index or -1 if not found.

bool FindAndReplace ( const char *  pFind,
const char *  pReplaceBy,
size_t  pStartPosition = 0  
)

Replace a substring.

Parameters:
pFind  The substring to look for.
pReplaceBy  The string to replace by.
pStartPosition  The start position.
Returns:
true if substring found and replaced.

bool ReplaceAll ( char  pFind,
char  pReplaceBy  
)

Replace a character.

Parameters:
pFind  The character to look for.
pReplaceBy  The character to replace by.
Returns:
true if character found and replaced.

int GetTokenCount ( const char *  pSpans  )  const

Get number of tokens.

Parameters:
pSpans  The span
Returns:
The number of tokens.

KString GetToken ( int  pTokenIndex,
const char *  pSpans  
) const

Get token at given index.

Parameters:
pTokenIndex  The token index.
pSpans  The span

static KMemoryAllocator* AllocatorGet (  )  [static]

Get new memory allocator.

static void AllocatorPurge (  )  [static]

Purge memory allocator.

static void AllocatorRelease (  )  [static]

Release memory allocator.


Friends And Related Function Documentation

KFBX_DLL KString operator+ ( const KString pKStr1,
const KString pKStr2  
) [friend]

KString concatenation.

Parameters:
pKStr1  The first KString to be concatenated.
pKStr2  The second KString to be concatenated.

KFBX_DLL KString operator+ ( const KString pKStr,
char  pChar  
) [friend]

Character concatenation.

Parameters:
pKStr  The KString be be concatenated.
pChar  The character to be concatenated.

KFBX_DLL KString operator+ ( const KString pKStr,
const char *  pStr  
) [friend]

String concatenation.

Parameters:
pKStr  The KString be be concatenated.
pStr  The string to be concatenated.

KFBX_DLL KString operator+ ( const KString pKStr,
int  pValue  
) [friend]

Int concatenation.

Parameters:
pKStr  The KString be be concatenated.
pValue  The int value be be concatenated.

KFBX_DLL KString operator+ ( const KString pKStr,
float  pValue  
) [friend]

Float concatenation.

Parameters:
pKStr  The KString be be concatenated.
pValue  The float value be be concatenated.
KString KString KString KString KString KString KString KString KString KString
KString KString KString KString KString KString KString KString KString KString